<?php

/**
 * 登录动作
 * @author liuzilu <fotomxq@gmail.com>
 * @version 1
 * @package center
 */
//引用全局
require('glob.php');

//失败返回信息
$faildMessage = '';

//处理登录
if (isset($_POST['u']) == true && isset($_POST['p']) == true) {
    //输入验证
    $remember = isset($_POST['r']);
    $postUserName = $filter->getEmail($_POST['u']);
    $postPassword = sha1($_POST['p']);
    //开始登录
    $loginReady = $user->login($ipAddr, $postUserName, $postPassword, $remember);
    if ($loginReady == true) {
        $log->add(basename(__FILE__), 'Sign in success.');
        if (count($appList) > 1) {
            CoreHeader::toURL('index.php');
            die();
        } else {
            foreach ($appList as $k => $v) {
                CoreHeader::toURL('app/' . $v['name'] . '/index.php');
                die();
            }
        }
        $faildMessage = 'app-null';
    } else {
        $log->add(basename(__FILE__), 'Sign in faild.');
        $faildMessage = 'login-faild';
    }
} else {
    $faildMessage = 'input-null';
}

//如果登录失败
CoreHeader::toURL('../../index.php?login-faild=' . $faildMessage);
?>